package com.xinsoft.controller.basic;


import com.xinsoft.aop.ano.SysLog;
import com.xinsoft.common.BusinessType;
import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysDictTypeParam;
import com.xinsoft.entity.po.SysDictionaryType;
import com.xinsoft.service.SysDictionaryService;
import com.xinsoft.service.SysDictionaryTypeService;
import com.xinsoft.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName SysDictTypeController
 * @Description 字典类型控制层
 * @Author lijie
 * @Date 2023年5月16日17:14:04
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/dict/type")
@Api(value = "SysDictTypeController", tags = {"字典类型控制层"})
public class SysDictTypeController {

    @Autowired
    private SysDictionaryTypeService dictionaryTypeService;

    @Autowired
    private SysDictionaryService dictionaryService;

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author Li9527
     * @Description 新增
     * @Date 2023/5/11 17:08
     * @params sysCompanyDTO
     **/
    @SysLog(title = "字典类型-新增", businessType = BusinessType.INSERT)
    @ApiOperation("新增")
    @PostMapping("/add")
    public Response<?> add(@RequestBody SysDictionaryType dictionaryType) {
        // 参数校验
        ValidatorUtils.validateEntity(dictionaryType);
        return Response.succeed(dictionaryTypeService.save(dictionaryType));
    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author Li9527
     * @Description 更新
     * @Date 2023/5/12 9:19
     * @params sysCompany
     **/
    @ApiOperation("更新")
    @SysLog(title = "字典类型-编辑", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<?> edit(@RequestBody SysDictionaryType dictionaryType) {
        // 参数校验
        ValidatorUtils.validateEntity(dictionaryType);
        return Response.succeed(dictionaryTypeService.updateById(dictionaryType));
    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author Li9527
     * @Description 获取详情
     * @Date 2023/5/12 9:20
     * @params id
     **/
    @ApiOperation("获取详情")
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(dictionaryTypeService.getById(id));
    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author Li9527
     * @Description 删除
     * @Date 2023/5/12 9:20
     * @params ids
     **/
    @ApiOperation("删除")
    @SysLog(title = "字典类型-删除", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public Response<?> del(@RequestBody List<Integer> ids) {
        dictionaryTypeService.removeByIds(ids);
        return Response.succeed();
    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author Li9527
     * @Description 分页
     * @Date 2023/5/16 17:31
     * @params sysUserPageParam
     **/
    @PostMapping("/pageList")
    public Response<?> pageList(@Valid @RequestBody SysDictTypeParam param) {
        return Response.succeed(dictionaryTypeService.findPageListByParam(param));
    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author Li9527
     * @Description 根据字典组id获取字典
     * @Date 2023/5/18 14:50
     * @params param
     **/
    @ApiOperation("根据字典组id获取字典")
    @PostMapping("/getDictByType")
    public Response<?> getDictByType(@Valid @RequestBody SysDictTypeParam param) {
        return Response.succeed(dictionaryService.findPageListByParam(param));
    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author Li9527
     * @Description 根据字典组code获取字典
     * @Date 2023/5/18 14:50
     * @params param
     **/
    @ApiOperation("根据字典组code获取字典")
    @PostMapping("/getDictByTypeCode")
    public Response<?> getDictByTypeCode(@Valid @RequestBody SysDictTypeParam param) {
        return Response.succeed(dictionaryService.getDictByTypeCode(param.getTypeCode()));
    }

}
